package com.probox.modules.controller.customer;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.customer.CustomerGroupDefinition;
import com.probox.common.entity.service.customer.ICustomerGroupDefinitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 客户分群定义信息Controller
 *
 * @author zsy
 * @date 2021-07-15
 */
@RestController
@RequestMapping("/customer/groupDefinition")
public class CustomerGroupDefinitionController extends BaseController {
    @Autowired
    private ICustomerGroupDefinitionService customerGroupDefinitionService;

    /**
     * 查询客户分群定义信息列表
     */
    @PreAuthorize(hasPermi = "groupDefinition:groupDefinition:list")
    @GetMapping("/list")
    public TableDataInfo list(CustomerGroupDefinition customerGroupDefinition) {
        startPage();
        List<CustomerGroupDefinition> list = customerGroupDefinitionService.queryList(customerGroupDefinition);
        return getDataTable(list);
    }

    /**
     * 导出客户分群定义信息列表
     */
    @PreAuthorize(hasPermi = "groupDefinition:groupDefinition:export")
    @Log(title = "客户分群定义信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerGroupDefinition customerGroupDefinition) throws IOException {
        List<CustomerGroupDefinition> list = customerGroupDefinitionService.queryList(customerGroupDefinition);
        ExcelUtil<CustomerGroupDefinition> util = new ExcelUtil<CustomerGroupDefinition>(CustomerGroupDefinition.class);
        util.exportExcel(response, list, "客户分群定义信息数据");
    }

    /**
     * 获取客户分群定义信息详细信息
     */
    @PreAuthorize(hasPermi = "groupDefinition:groupDefinition:query")
    @GetMapping(value = "/{definitionUid}")
    public AjaxResult getInfo(@PathVariable("definitionUid") Long definitionUid) {
        return AjaxResult.success(customerGroupDefinitionService.selectCustomerGroupDefinitionById(definitionUid));
    }

    /**
     * 新增客户分群定义信息
     */
    @PreAuthorize(hasPermi = "groupDefinition:groupDefinition:add")
    @Log(title = "客户分群定义信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerGroupDefinition customerGroupDefinition) {
        return toAjax(customerGroupDefinitionService.insertCustomerGroupDefinition(customerGroupDefinition));
    }

    /**
     * 修改客户分群定义信息
     */
    @PreAuthorize(hasPermi = "groupDefinition:groupDefinition:edit")
    @Log(title = "客户分群定义信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerGroupDefinition customerGroupDefinition) {
        return toAjax(customerGroupDefinitionService.updateCustomerGroupDefinition(customerGroupDefinition));
    }

    /**
     * 删除客户分群定义信息
     */
    @PreAuthorize(hasPermi = "groupDefinition:groupDefinition:remove")
    @Log(title = "客户分群定义信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{definitionUids}")
    public AjaxResult remove(@PathVariable Long[] definitionUids) {
        return toAjax(customerGroupDefinitionService.deleteCustomerGroupDefinitionByIds(definitionUids));
    }

    /**
     * 修改客户分群特征状态
     */
    @PreAuthorize(hasPermi = "groupDefinition:groupDefinition:edit")
    @Log(title = "客户分群定义信息", businessType = BusinessType.UPDATE)
    @PutMapping("/updateGroupDefinitionStatus")
    public AjaxResult updateGroupDefinitionStatus(@RequestBody CustomerGroupDefinition customerGroupDefinition) {
        return toAjax(customerGroupDefinitionService.updateCustomerGroupDefinition(customerGroupDefinition));
    }

    /**
     * 查询所有特征信息
     */
    @PreAuthorize(hasPermi = "groupDefinition:groupDefinition:query")
    @GetMapping(value = "/getAllDefinitionInfo")
    public AjaxResult getAllDefinitionInfo() {
        return AjaxResult.success(customerGroupDefinitionService.getAllDefinitionInfo());
    }

}
